<?php

require_once 'Sql.php';
require_once 'common.php';

class Entity {

    var $conDB;

    function __construct() {
        $this->conDB = new Sql();
    }

    public function select($query) {
        $rs = @mysql_query($query);
        $result = array();
        while ($record = @mysql_fetch_array($rs))
            $result[] = $record;
        @mysql_free_result($rs);
        return $result;
    }

    public function update($query) {
        $result = @mysql_query($query);
        @mysql_free_result($result);
    }
    
    public function insert($query){
        $result = @mysql_query($query);
        $id=  mysql_insert_id();
        @mysql_free_result($result);
        return $id;
    }
    
    public function remove($query){
        $result = @mysql_query($query);
        @mysql_free_result($result);
    }
    
    public function paging($query,$from,$limit,$charpaging,$pagename){
	$entity= new Entity();
	$list=$entity->select($query);
	$count=count($list);
        if($count > $limit){
	$page=(int)($count/$limit);
	echo "<a href='".$pagename."'>Trang Đầu</a>".$charpaging;
	for($i=0;$i<(int)$page;$i++){
		//echo "<a href='#'>".($i+1)."</a>".$charpaging;
            $check="";
            if(($from>=$i*$limit&&$from<$i*($limit+1))||($from==0&$i==0)){
                echo "<span style='color:#F60;font-weight:bold'> ".($i+1) ."</span>".$charpaging;
            }else{
            
		echo "<a  href='".$pagename."_".$i*$limit."_".$limit."'> ".($i+1) ." </a>".$charpaging;
		//$re=$re."<a href='".$_SERVER["SERVER_NAME"].$pagename."?from=".$i*$limit."&limit=".$limit."'> ".$i+1 ." </a>".$charpaging;

            }}
	echo "<a href='".$pagename."_".$page*$limit."_".$limit."'>Trang Cuối</a>";
        }
}
    public function pagingbk($query,$from,$limit,$charpaging,$pagename){
	$entity= new Entity();
	$list=$entity->select($query);
	$count=count($list);
        if($count > $limit){
	$page=(int)($count/$limit);
	echo "<a href='".$pagename."'>Trang Đầu</a>".$charpaging;
	for($i=0;$i<(int)$page;$i++){
		//echo "<a href='#'>".($i+1)."</a>".$charpaging;
            $check="";
            if(($from>=$i*$limit&&$from<$i*($limit+1))||($from==0&$i==0)){
                echo "<span style='color:#F60;font-weight:bold'> ".($i+1) ."</span>".$charpaging;
            }else{
            
		echo "<a  href='".$pagename."&from=".$i*$limit."&limit=".$limit."'> ".($i+1) ." </a>".$charpaging;
		//$re=$re."<a href='".$_SERVER["SERVER_NAME"].$pagename."?from=".$i*$limit."&limit=".$limit."'> ".$i+1 ." </a>".$charpaging;

            }}
	echo "<a href='".$pagename."&from=".$page*$limit."&limit=".$limit."'>Trang Cuối</a>";
        }
}

}

?>
